/*
 * @Description:
 * @Author: wangqi
 * @Date: 2024-09-07 17:55:35
 * @LastEditTime: 2024-09-08 17:21:21
 * @LastEditAuthor: wangqi
 */
import { Logger } from '@nestjs/common';
import { ArgumentsHost, ExceptionFilter, HttpException } from '@nestjs/common';

export class HttpExceptionFilter implements ExceptionFilter {
  private readonly logger = new Logger();
  constructor() {}

  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    const request = ctx.getRequest();
    const status = exception.getStatus();
    // this.logger.warn(exception.message, exception.stack);
    console.log('hahah哈哈哈');
    this.logger.warn(exception.message, '我是谁~');

    response.status(status).json({
      statusCode: status,
      timestamp: new Date().toISOString(),
      path: request.url,
      message: exception.message,
    });
  }
}
